/**
 * 
 */
package com.hexacta.hrs.spring;


import org.vectrics.domain.Domain;
import org.vectrics.hibernate.ThreadProperties;

import com.hexacta.hrs.repositories.RecordObjectRepository;

/**
 * Objeto encargado de traer el Domain.
 * @author mfunes
 *
 */
public final class DomainRetriever {

    private RecordObjectRepository<Domain> domainGenericRepository;
    
    public void setDomainGenericRepository(RecordObjectRepository<Domain> domainGenericRepository) {
        this.domainGenericRepository = domainGenericRepository;
    }

    /**
     * Devuelve el domain actual que tiene le usuario logueado.
     * @return el domain o null si no existe.
     */
    public Domain getDomain(){
        Domain result = null;
        Domain threadDomain = ThreadProperties.getDomain();
        if ( threadDomain != null && threadDomain.getId() != null){
            result = domainGenericRepository.forId(threadDomain.getId());
        }        
        return  result;
    }

}
